package vn.edu.hungvuongaptech.dao;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import vn.edu.hungvuongaptech.common.Constant;
import vn.edu.hungvuongaptech.model.StatusModel;
import vn.edu.hungvuongaptech.model.UserModel;
import vn.edu.hungvuongaptech.util.DataUtil;

public class StatusDAO {

	/**
	 * Get All Statuses.
	 * @return ArrayList<StatusModel>
	 */
	public static ArrayList<StatusModel> getAllStatuses() {
		ArrayList<StatusModel> statusModelList = new ArrayList<StatusModel>();
		try {
			String sql = Constant.SQL_RES.getString("timesheet.sql.getAllStatuses");
			ResultSet rs = DataUtil.executeQuery(sql);
			StatusModel statusModel = null;
			while (rs.next()) {
				statusModel = new StatusModel();
				statusModel.setStatusId(rs.getInt("StatusId"));
				statusModel.setStatusName(rs.getString("StatusName"));
				statusModel.setStatusDescription(rs.getString("StatusDescription"));
				statusModelList.add(statusModel);
			}
			return statusModelList;
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return null;
	}
	
	public static StatusModel getStatusById(long statusID) {
		try {
			StatusModel statusModel = new StatusModel();
			PreparedStatement statement = DataUtil
					.getConnection()
					.prepareStatement(
							Constant.SQL_RES
									.getString("timesheet.sql.getStatusById"));
			statement.setLong(1, statusID);
			ResultSet rs = statement.executeQuery();			
			while (rs.next()) {				
				statusModel.setStatusId(rs.getInt("StatusId"));
				statusModel.setStatusName(rs.getString("StatusName"));
				statusModel.setStatusDescription(rs.getString("StatusDescription"));			
			}
			return statusModel;
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return null;
	}
}
